package com.avic.rong.listener;

import android.support.v4.widget.NestedScrollView;

import com.orhanobut.logger.Logger;

/**
 * Creater: Created by wangyz on 2019/9/26.
 * Email: 936804097@qq.com
 */
public class RocketOnScrollListener implements NestedScrollView.OnScrollChangeListener {


    public RocketOnScrollListener(ScrollCallBackInterface callBackInterface) {
        this.callBackInterface = callBackInterface;
    }

    @Override
    public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {


        if (scrollY == 0) {
            // 顶部
            Logger.i("------------------顶部");
            if (callBackInterface != null){
                callBackInterface.onTop();
            }
        }

        if (scrollY == (v.getChildAt(0).getMeasuredHeight() - v.getMeasuredHeight())) {
            // 底部
            Logger.i("------------------底部");
        }

        if (scrollY > 700){
            if (scrollY > oldScrollY) {
                // 向下滑动
                Logger.i("------------------向下滑动");
                if (callBackInterface != null){
                    callBackInterface.onDowning();
                }
            }
        }


        if (scrollY > 700){
            if (scrollY < oldScrollY) {
                // 向上滑动
                Logger.i("------------------向上滑动");
            }
        }
    }


    private ScrollCallBackInterface callBackInterface;

    public void setCallBackInterface(ScrollCallBackInterface callBackInterface) {
        this.callBackInterface = callBackInterface;
    }

    public interface ScrollCallBackInterface{
        void onTop();
        void onDowning();
    }



}
